package com.automobile.service.impl;

import com.automobile.dao.SmartDao;
import com.automobile.domain.Smart;
import com.automobile.service.SmartService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.annotation.Id;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 智能汽车
 *
 * @author liujiamiao
 * @email 2544296058@qq.com
 * @date 2020-03-25 18:50
 */
@CacheConfig(cacheManager = "redisCacheManager",cacheNames = {"smart"})
@Service("smartService")
public class SmartServiceImpl implements SmartService {

    @Autowired
    private SmartDao smartDao;

    @Override
    public List<Smart> query(String title,int page,int size) {

        PageHelper.startPage(page,size);
        return smartDao.query("%"+title+"%");
    }

    @Cacheable(key = "#id")
    @Override
    public Smart findById(int id) {
        return smartDao.findById(id);
    }

    //一下是后台管理的功能

    @Override
    public List<Smart> findAll(int page, int size) {
        PageHelper.startPage(page,size);
        return smartDao.findAll();
    }

    @Override
    public void delete(int id) {
        smartDao.delete(id);
    }

    @Override
    public void delete(List<Integer> ids) {
        for(int id : ids){
            smartDao.delete(id);
        }
    }

    @Override
    public void save(Smart smart) {
        smartDao.save(smart);
    }

    @Override
    public void update(Smart smart) {
        smartDao.update(smart);
    }

    @Override
    public void updateStatus(int status, int id) {
        smartDao.updateStatus(status,id);
    }
}
